package com.moyuwanjia.ui;

import com.moyuwanjia.pojo.User;
import com.moyuwanjia.service.UserService;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author 摸鱼丸加~
 * @create 2022-04-19 11:26
 * 模拟表现层，用于调用业务层
 */
public class Client01_applicationContext {
    public static void main(String[] args) {
        ClassPathXmlApplicationContext classPathXmlApplicationContext = new ClassPathXmlApplicationContext("bean.xml");

        //演示数据的注入方式
        UserService userService1 = (UserService) classPathXmlApplicationContext.getBean("userServiceImpl");
        System.out.println(userService1.saveUsers(new User("张三")));

        //演示Scope注解的作用域范围
        UserService userService2 = (UserService) classPathXmlApplicationContext.getBean("userServiceImpl");
        UserService userService3 = (UserService) classPathXmlApplicationContext.getBean("userServiceImpl");
        System.out.println(userService2+"\n"+userService3);
        System.out.println(userService1 == userService2);

//        UserDao userDao01 = (UserDao) classPathXmlApplicationContext.getBean("userDao01");
//        System.out.println(userDao01);
//
//        UserDao userDao02 =  classPathXmlApplicationContext.getBean("userDao02", UserDaoImpl02.class);
//        System.out.println(userDao02);

//        userService1.saveUsers(new User());

//      关闭此应用程序上下文，销毁其bean工厂中的所有bean。
        classPathXmlApplicationContext.close();




    }
}
